%% On the Optimal Design of Transfers and Income-Tax Progressivity
% Read and plot how aggregates move along the transition

clear; clc; close all;
addpath('../../../../Matlab_Figure_Files');

%% Read Results

% Aggregate capital along the transition
Kagg_TR = dlmread('Kagg_TR.txt')';
Kagg_TR = Kagg_TR(:);

% Efficiency units of labor along the transition
Lagg_TR = dlmread('Lagg_TR.txt')';
Lagg_TR = Lagg_TR(:);

% Prices (and capital and output) in intial and final steady states
prices_INIT = dlmread('Prices_INIT.txt');
prices_LR = dlmread('Prices_LR.txt');

% Interest rate along transition
r_TR = dlmread('r_TR.txt')';
r_TR = r_TR(:);

Tt = numel(r_TR)+2;

%% Create time series to be plotted

% Interest rate (including steady states)
r_TR_long = [prices_INIT(1,2);r_TR;prices_LR(1,2)];

% Wages (including steady states)
alpha = 0.64;
delta = 0.06;
wge_TR_long = (1-alpha)./(r_TR_long+delta);
wge_TR_long = alpha*(wge_TR_long.^((1-alpha)/alpha));

% Capital
Kagg_TR_long = [prices_INIT(1,3);Kagg_TR;prices_LR(1,3)];

% Output
Yagg_TR_long = [prices_INIT(2,1);Kagg_TR.^(1-alpha).*Lagg_TR.^alpha;prices_LR(2,1)];

%% Plot

xub = 60;       % upper bound for x-axis

fig = figure(101);
% Interest rate
subplot(2,2,1)
plot((0:Tt-1)',100*(r_TR_long-r_TR_long(1)),'LineWidth',2); hold on
plot((0:Tt-1)',0*(wge_TR_long),'k','LineStyle',':','LineWidth',2)
yticks([-2 0 2])
yticklabels({'-2','0','2'})
ylabel('$\Delta r$ (p.p.)','Interpreter','LaTex','Fontsize',12)
xlim([0 xub])
ylim([-2 3])
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
% Wage
subplot(2,2,2)
plot((0:Tt-1)',100*(wge_TR_long-wge_TR_long(1))/wge_TR_long(1),'LineWidth',2); hold on
plot((0:Tt-1)',0*(wge_TR_long),'k','LineStyle',':','LineWidth',2);
ylabel('$\Delta w$ (\%)','Interpreter','LaTex','Fontsize',12)
xlim([0 xub])
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
% Capital
subplot(2,2,3)
plot((0:Tt-1)',100*(Kagg_TR_long-Kagg_TR_long(1))/Kagg_TR_long(1),'LineWidth',2); hold on
plot((0:Tt-1)',0*(wge_TR_long),'k','LineStyle',':','LineWidth',2);
ylabel('$\Delta K$ (\%)','Interpreter','LaTex','Fontsize',12)
xlabel('Period','Interpreter','LaTex','Fontsize',12)
xlim([0 xub])
ylim([-40 0])
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
% Output
subplot(2,2,4)
plot((0:Tt-1)',100*(Yagg_TR_long-Yagg_TR_long(1))/Yagg_TR_long(1),'LineWidth',2); hold on
plot((0:Tt-1)',0*(wge_TR_long),'k','LineStyle',':','LineWidth',2);
ylabel('$\Delta Y$ (\%)','Interpreter','LaTex','Fontsize',12)
xlabel('Period','Interpreter','LaTex','Fontsize',12)
xlim([0 xub])
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
run graph_extended.m;
saveas(gcf,'qm_transition_agg.pdf')


fig = figure(102);
% Interest rate
subplot(2,2,1)
plot((0:Tt-1)',100*(r_TR_long-r_TR_long(1)),'LineWidth',2,'Color',[0 0 0]); hold on
plot((0:Tt-1)',0*(wge_TR_long),'k','LineStyle',':','LineWidth',2)
yticks([-2 0 2])
yticklabels({'-2','0','2'})
ylabel('$\Delta r$ (p.p.)','Interpreter','LaTex','Fontsize',12)
xlim([0 xub])
ylim([-2 3])
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
% Wage
subplot(2,2,2)
plot((0:Tt-1)',100*(wge_TR_long-wge_TR_long(1))/wge_TR_long(1),'LineWidth',2,'Color',[0 0 0]); hold on
plot((0:Tt-1)',0*(wge_TR_long),'k','LineStyle',':','LineWidth',2);
ylabel('$\Delta w$ (\%)','Interpreter','LaTex','Fontsize',12)
xlim([0 xub])
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
% Capital
subplot(2,2,3)
plot((0:Tt-1)',100*(Kagg_TR_long-Kagg_TR_long(1))/Kagg_TR_long(1),'LineWidth',2,'Color',[0 0 0]); hold on
plot((0:Tt-1)',0*(wge_TR_long),'k','LineStyle',':','LineWidth',2);
ylabel('$\Delta K$ (\%)','Interpreter','LaTex','Fontsize',12)
xlabel('Period','Interpreter','LaTex','Fontsize',12)
xlim([0 xub])
ylim([-40 0])
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
% Output
subplot(2,2,4)
plot((0:Tt-1)',100*(Yagg_TR_long-Yagg_TR_long(1))/Yagg_TR_long(1),'LineWidth',2,'Color',[0 0 0]); hold on
plot((0:Tt-1)',0*(wge_TR_long),'k','LineStyle',':','LineWidth',2);
ylabel('$\Delta Y$ (\%)','Interpreter','LaTex','Fontsize',12)
xlabel('Period','Interpreter','LaTex','Fontsize',12)
xlim([0 xub])
set(gca,'XGrid','off','YGrid','on','Fontsize',12) 
set(gca,'TickLabelInterpreter','LaTex')
run graph_extended.m;
saveas(gcf,'qm_transition_agg_bw.pdf')
saveas(gcf,'qm_transition_agg_bw','epsc')


